package wdt_qf.job;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import wdt_qf.dao.AuditingDao;
import wdt_qf.dao.ZxyNeedauditingretailsbillidDao;
import wdt_qf.entity.wdt.*;
import wdt_qf.service.WdtService;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Component
@EnableScheduling
@EnableAsync
@Slf4j
public class GetBill {
    @Resource
    private WdtService wdtService;

    @Scheduled(fixedDelay = 60000)  //间隔1秒1000
    public void getSaleBill() {
        int minuts = 2;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtSaleQueryInfo wdtSaleQueryInfo = new WdtSaleQueryInfo();
        wdtSaleQueryInfo.setStatus(110);
        wdtSaleQueryInfo.setStart_time(Start_time);
        wdtSaleQueryInfo.setEnd_time(end_time);
        wdtSaleQueryInfo.setPage_no(0);
        wdtSaleQueryInfo.setPage_size(100);
        wdtSaleQueryInfo.setSetSrcOrderNo("");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill = wdtService.getWdtSaleBill(wdtSaleQueryInfo);
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill2 = wdtService.getWdtSaleBill2(wdtSaleQueryInfo);
    }

    //    @Scheduled(fixedDelay = 12000)  //间隔1秒1000
    public void getSaleBackBill() {
        int minuts = 30;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtSaleQueryInfo wdtSaleBackQueryInfo = new WdtSaleQueryInfo();
        wdtSaleBackQueryInfo.setStatus(80);
        wdtSaleBackQueryInfo.setStart_time(Start_time);
        wdtSaleBackQueryInfo.setEnd_time(end_time);
        wdtSaleBackQueryInfo.setPage_no(0);
        wdtSaleBackQueryInfo.setPage_size(100);
        wdtSaleBackQueryInfo.setSetSrcOrderNo("");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBackBill = wdtService.getWdtSaleBackBill(wdtSaleBackQueryInfo);
    }


    //获取其他出库单1
    @Scheduled(fixedDelay = 600000)  //间隔1秒1000
    public void getOtherOutStock() {
        int minuts = 10;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtOtherOutStockQueryInfo wdtSaleQueryInfo = new WdtOtherOutStockQueryInfo();
        wdtSaleQueryInfo.setStatus(0);
        wdtSaleQueryInfo.setStart_time(Start_time);
        wdtSaleQueryInfo.setEnd_time(end_time);
        wdtSaleQueryInfo.setPage_no(0);
        wdtSaleQueryInfo.setPage_size(100);
        wdtSaleQueryInfo.setWarehouseNo("XLTX");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill = wdtService.getWdtOtherOutStockBill(wdtSaleQueryInfo);
    }

    //获取其他出库单2
    @Scheduled(fixedDelay = 660000)  //间隔1秒1000
    public void getOtherOutStock2() {
        int minuts = 11;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtOtherOutStockQueryInfo wdtSaleQueryInfo = new WdtOtherOutStockQueryInfo();
        wdtSaleQueryInfo.setStatus(0);
        wdtSaleQueryInfo.setStart_time(Start_time);
        wdtSaleQueryInfo.setEnd_time(end_time);
        wdtSaleQueryInfo.setPage_no(0);
        wdtSaleQueryInfo.setPage_size(100);
        wdtSaleQueryInfo.setWarehouseNo("SH");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill = wdtService.getWdtOtherOutStockBill(wdtSaleQueryInfo);
    }



    //获取盘点单据
//    @Scheduled(cron = "0 58 10 * * ?")
    public void getPdBil1() {
        int minuts = 180;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtPdBillQueryInfo wdtPdBillQueryInfo = new WdtPdBillQueryInfo();
        wdtPdBillQueryInfo.setStart_time(Start_time);
        wdtPdBillQueryInfo.setEnd_time(end_time);
        wdtPdBillQueryInfo.setPage_no(0);
        wdtPdBillQueryInfo.setPage_size(100);
        wdtPdBillQueryInfo.setWarehouse_no("SH");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill = wdtService.getWdtPDBill(wdtPdBillQueryInfo);
        log.info("定时器返回SH仓库的盘点的盘点信息:"+ JSON.toJSONString(wdtSaleBill));
    }
    //获取盘点单据
//    @Scheduled(cron = "0 59 10 * * ?")
    public void getPdBil2() {
        int minuts = 182;
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now2 = now.minusMinutes(minuts);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String Start_time = now2.format(formatter);
        String end_time = now.format(formatter);
        WdtPdBillQueryInfo wdtPdBillQueryInfo = new WdtPdBillQueryInfo();
        wdtPdBillQueryInfo.setStart_time(Start_time);
        wdtPdBillQueryInfo.setEnd_time(end_time);
        wdtPdBillQueryInfo.setPage_no(0);
        wdtPdBillQueryInfo.setPage_size(100);
        wdtPdBillQueryInfo.setWarehouse_no("XLTX");
        WdtHttpResult<WdtSaleBillRes> wdtSaleBill = wdtService.getWdtPDBill(wdtPdBillQueryInfo);
        log.info("定时器返回XLTX仓库的盘点的盘点信息:"+ JSON.toJSONString(wdtSaleBill));
    }

}
